<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('scm_companies');
        Schema::create('scm_companies', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->string('name', 191)->index()->nullable()->comment('名称');
            $table->string('alias', 191)->index()->nullable()->comment('别名');
            $table->text('introduce')->nullable()->comment('介绍');
            $table->text('config_data')->fulltext()->nullable()->comment('配置数据，格式为json');
            $table->mediumText('detail')->nullable()->comment('详细信息');
            $table->bigInteger('org_id')->index()->default(0)->comment('组织ID');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_companies comment 'SCM 公司表';");

        Schema::dropIfExists('scm_communities');
        Schema::create('scm_communities', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->string('name', 191)->index()->nullable()->comment('名称');
            $table->string('alias', 191)->index()->nullable()->comment('别名');
            $table->text('introduce')->nullable()->comment('介绍');
            $table->text('config_data')->fulltext()->nullable()->comment('配置数据，格式为json');
            $table->mediumText('detail')->nullable()->comment('详细信息');
            $table->bigInteger('org_id')->index()->default(0)->comment('组织ID');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_communities comment 'SCM 社区表';");

        Schema::dropIfExists('scm_buildings');
        Schema::create('scm_buildings', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->string('name', 191)->index()->nullable()->comment('名称');
            $table->string('alias', 191)->index()->nullable()->comment('别名');
            $table->unsignedInteger('building_type')->default(1)->comment('建筑类型');
            $table->integer('floor')->default(1)->comment('楼层');
            $table->unsignedDouble('building_area', 18, 4)->default(0)->comment('建筑面积');
            $table->unsignedDouble('chargeable_area', 18, 4)->default(0)->comment('收费面积');
            $table->integer('parking_space_capacity')->default(0)->comment('可停车数量');
            $table->unsignedInteger('can_register')->default(1)->comment('可注册');
            $table->unsignedInteger('can_sell')->default(0)->comment('可出售');
            $table->unsignedInteger('can_lease')->default(0)->comment('可出租');
            $table->unsignedInteger('sell_status')->default(0)->comment('销售状态');
            $table->unsignedInteger('lease_status')->default(0)->comment('出租状态');
            $table->text('introduce')->nullable()->comment('介绍');
            $table->text('config_data')->fulltext()->nullable()->comment('配置数据，格式为json');
            $table->mediumText('detail')->nullable()->comment('详细信息');
            $table->bigInteger('org_id')->index()->default(0)->comment('组织ID');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_buildings comment 'SCM 建筑表';");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
};
